﻿namespace Creek.UI.EFML.Base.JS.ScriptingTypes
{
    using System.Collections.Generic;
    using System.Dynamic;
    using System.Windows.Forms;

    public class DocumentAll : DynamicObject
    {
        #region Fields

        private readonly Dictionary<string, object> _properties = new Dictionary<string, object>();

        #endregion

        #region Constructors and Destructors

        public DocumentAll(FlowLayoutPanel b)
        {
            foreach (Control c in b.Controls)
            {
                this._properties.Add(c.Name, c);
            }
        }

        #endregion

        #region Public Indexers

        public object this[string k]
        {
            get
            {
                return this._properties[k];
            }
            set
            {
                this._properties[k] = value;
            }
        }

        #endregion

        #region Public Methods and Operators

        public override IEnumerable<string> GetDynamicMemberNames()
        {
            return this._properties.Keys;
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            return this._properties.TryGetValue(binder.Name, out result);
        }

        public override bool TrySetMember(SetMemberBinder binder, object Content)
        {
            this._properties[binder.Name] = Content;
            return true;
        }

        #endregion
    }
}